/*
 * pings.h
 *
 *  Created on: 2008-8-12
 *      Author: root
 */

#ifndef PINGS_H_
#define PINGS_H_

#include <netinet/in_systm.h>
#include <netinet/ip.h>
#include <netinet/ip_icmp.h>
#include <sys/types.h>
#include <time.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <signal.h>
#include <sys/time.h>
#include <sys/socket.h>
#include <errno.h>
#include <netdb.h>							//struct addrinfo
#include <arpa/inet.h>

#include "../msgqueue/MsgQue.h"

#include <iostream>
using namespace std;

#define BUFSIZE	1500

char 		recvbuf4[BUFSIZE];
char 		recvbuf6[BUFSIZE];
char 		sendbuf[BUFSIZE];

int 		datalen = 56;				// bytes of data followed by ICMP HEADER
//char 		*host;
int 		nsent;				// add 1 for each sentto()
const pid_t 		pid = getpid();
int 		sockfd4, sockfd6;			// for IPv4 & IPv6

unsigned short in_cksum(unsigned short *, int);

void proc_v4(char *, ssize_t, struct timeval *);
void proc_v6(char *, ssize_t, struct timeval *);

void send_v4(int);
void send_v6(int);

void readloop(void);
void sig_alrm(int);									//work as timer
void tv_sub(struct timeval *, struct timeval *);			//calculate RTT
struct addrinfo *host_serv(const char *, const char *, int, int);

char *sock_ntop_host(struct sockaddr *, socklen_t);

void print_it(char *, int);

void resetStatistics(void);

struct proto
{
	int sockFd;
	void (*fproc)(char *, ssize_t, struct timeval *);
	void (*fsend)(int);
	struct sockaddr *sasend;				// *sockaddr{} for send, get from getaddrinfo
	struct sockaddr *sarecv;				//for receiving
	socklen_t	salen;							// length of sockaddr
	int icmpproto;								// IPPROTO_xxx value for ICMP
} *pr4, *pr6;

//#ifdef	IPV6
#include <netinet/ip6.h>
#include <netinet/icmp6.h>
//#endif

#endif /* PINGS_H_ */
